﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package reprise.css.propertyparsers {
    import reprise.css.*;
    import reprise.utils.*;
    import reprise.css.transitions.*;

    public class Border extends CSSPropertyParser {

        public static const BORDER_STYLE_DASHED:String = "dashed";
        public static const BORDER_STYLE_SOLID:String = "solid";
        public static const BORDER_STYLE_DOTTED:String = "dotted";
        public static const KNOWN_PROPERTIES:Object = {border:{parser:parseBorder}, borderTop:{parser:parseBorderTop}, borderRight:{parser:parseBorderRight}, borderBottom:{parser:parseBorderBottom}, borderLeft:{parser:parseBorderLeft}, borderStyle:{parser:parseBorderStyle}, borderColor:{parser:parseBorderColor}, borderWidth:{parser:parseBorderWidth}, borderTopWidth:{parser:strToIntProperty}, borderRightWidth:{parser:strToIntProperty}, borderBottomWidth:{parser:strToIntProperty}, borderLeftWidth:{parser:strToIntProperty}, borderTopStyle:{parser:strToStringProperty}, borderRightStyle:{parser:strToStringProperty}, borderBottomStyle:{parser:strToStringProperty}, borderLeftStyle:{parser:strToStringProperty}, borderTopColor:{parser:strToColorProperty, transition:ColorTransitionVO}, borderRightColor:{parser:strToColorProperty, transition:ColorTransitionVO}, borderBottomColor:{parser:strToColorProperty, transition:ColorTransitionVO}, borderLeftColor:{parser:strToColorProperty, transition:ColorTransitionVO}, borderRenderer:{parser:strToStringProperty}, borderRadius:{parser:parseBorderRadius}, borderTopLeftRadius:{parser:strToIntProperty}, borderTopRightRadius:{parser:strToIntProperty}, borderBottomRightRadius:{parser:strToIntProperty}, borderBottomLeftRadius:{parser:strToIntProperty}};
        public static const BORDER_STYLE_NONE:String = "none";

        public static var TRANSITION_SHORTCUTS:Object = {border:["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth", "borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"], borderWidth:["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"], borderColor:["borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"], borderTop:["borderTopWidth", "borderTopColor"], borderRight:["borderRightWidth", "borderRightColor"], borderBottom:["borderBottomWidth", "borderBottomColor"], borderLeft:["borderLeftWidth", "borderLeftColor"], borderRadius:["borderTopLeftRadius", "borderTopRightRadius", "borderBottomRightRadius", "borderBottomLeftRadius"]};

        public static function parseBorderRadius(_arg1:String, _arg2:String):CSSParsingResult{
            var _local6:CSSProperty;
            var _local7:CSSProperty;
            var _local8:CSSProperty;
            var _local9:CSSProperty;
            var _local3:Object = CSSParsingHelper.removeImportantFlagFromString(_arg1);
            var _local4:Boolean = _local3.important;
            _arg1 = _local3.result;
            var _local5:Array = _arg1.split(" ");
            switch (_local5.length){
                case 1:
                    _local9 = strToIntProperty(_local5[0], _arg2);
                    _local8 = _local9;
                    _local7 = _local8;
                    _local6 = _local7;
                    break;
                case 2:
                    _local8 = strToIntProperty(_local5[0], _arg2);
                    _local6 = _local8;
                    _local9 = strToIntProperty(_local5[1], _arg2);
                    _local7 = _local9;
                    break;
                case 3:
                    _local6 = strToIntProperty(_local5[0], _arg2);
                    _local9 = strToIntProperty(_local5[1], _arg2);
                    _local7 = _local9;
                    _local8 = strToIntProperty(_local5[2], _arg2);
                    break;
                case 4:
                    _local6 = strToIntProperty(_local5[0], _arg2);
                    _local7 = strToIntProperty(_local5[1], _arg2);
                    _local8 = strToIntProperty(_local5[2], _arg2);
                    _local9 = strToIntProperty(_local5[3], _arg2);
                    break;
                default:
                    log((("w Border::parseBorderWidth: wrong number of " + "parameters in: ") + _arg1));
                    return (null);
            };
            _local6.setImportant(_local4);
            _local7.setImportant(_local4);
            _local8.setImportant(_local4);
            _local9.setImportant(_local4);
            return (CSSParsingResult.ResultWithPropertiesAndKeys(_local6, "borderTopLeftRadius", _local7, "borderTopRightRadius", _local8, "borderBottomRightRadius", _local9, "borderBottomLeftRadius"));
        }
        public static function parseBorderWidth(_arg1:String, _arg2:String):CSSParsingResult{
            return (strToRectParsingResult(_arg1, _arg2, "border", "Width", strToIntProperty));
        }
        protected static function parseBorderForSide(_arg1:String, _arg2:String, _arg3:String):CSSParsingResult{
            var _local11:CSSProperty;
            var _local4:CSSParsingResult = new CSSParsingResult();
            var _local5:Object = CSSParsingHelper.removeImportantFlagFromString(_arg1);
            var _local6:String = (_local5.important) ? CSSProperty.IMPORTANT_FLAG : "";
            _arg1 = _local5.result;
            var _local7:Object = extractBorderStyleFromString(_arg1, _arg3);
            var _local8:CSSProperty = _local7.borderStyle;
            _arg1 = _local7.filteredString;
            if (_arg2 == ""){
                _local4.addPropertyForKey(_local8, "borderTopStyle");
                _local4.addPropertyForKey(_local8, "borderRightStyle");
                _local4.addPropertyForKey(_local8, "borderBottomStyle");
                _local4.addPropertyForKey(_local8, "borderLeftStyle");
            } else {
                _local4.addPropertyForKey(_local8, (("border" + _arg2) + "Style"));
            };
            _local7 = extractBorderWidthFromString(_arg1, _arg3);
            var _local9:CSSProperty = _local7.borderWidth;
            _arg1 = StringUtil.lTrim(_local7.filteredString);
            if (_arg2 == ""){
                _local4.addPropertyForKey(_local9, "borderTopWidth");
                _local4.addPropertyForKey(_local9, "borderRightWidth");
                _local4.addPropertyForKey(_local9, "borderBottomWidth");
                _local4.addPropertyForKey(_local9, "borderLeftWidth");
            } else {
                _local4.addPropertyForKey(_local9, (("border" + _arg2) + "Width"));
            };
            var _local10:Array = _arg1.split(" ");
            if (_local10.length){
                _local11 = strToColorProperty((String(_local10.shift()) + _local6), _arg3);
                if (_arg2 == ""){
                    _local4.addPropertyForKey(_local11, "borderTopColor");
                    _local4.addPropertyForKey(_local11, "borderRightColor");
                    _local4.addPropertyForKey(_local11, "borderBottomColor");
                    _local4.addPropertyForKey(_local11, "borderLeftColor");
                } else {
                    _local4.addPropertyForKey(_local11, (("border" + _arg2) + "Color"));
                };
            };
            return (_local4);
        }
        public static function parseBorderRight(_arg1:String, _arg2:String):CSSParsingResult{
            return (parseBorderForSide(_arg1, "Right", _arg2));
        }
        public static function parseBorderLeft(_arg1:String, _arg2:String):CSSParsingResult{
            return (parseBorderForSide(_arg1, "Left", _arg2));
        }
        public static function parseBorderBottom(_arg1:String, _arg2:String):CSSParsingResult{
            return (parseBorderForSide(_arg1, "Bottom", _arg2));
        }
        public static function parseBorderColor(_arg1:String, _arg2:String):CSSParsingResult{
            return (strToRectParsingResult(_arg1, _arg2, "border", "Color", strToColorProperty));
        }
        public static function parseBorderStyle(_arg1:String, _arg2:String):CSSParsingResult{
            return (strToRectParsingResult(_arg1, _arg2, "border", "Style", strToStringProperty));
        }
        public static function parseBorderTop(_arg1:String, _arg2:String):CSSParsingResult{
            return (parseBorderForSide(_arg1, "Top", _arg2));
        }
        public static function parseBorder(_arg1:String, _arg2:String):CSSParsingResult{
            return (parseBorderForSide(_arg1, "", _arg2));
        }

    }
}//package reprise.css.propertyparsers 
